package net.tv90.auth.utils.encrypt;

import java.nio.charset.StandardCharsets;
import java.util.Base64;

public class Base64DaoEncryptService implements DaoEncryptService {

    @Override
    public String encrypt(String content) {
        try {
            String result = Base64.getEncoder().encodeToString(content.getBytes(StandardCharsets.UTF_8));
            return result;
        } catch (Exception e) {
            throw new RuntimeException("加密失败", e);
        }
    }

    @Override
    public String decrypt(String content) {
        try {
            byte[] asBytes = Base64.getDecoder().decode(content);
            String result = new String(asBytes, StandardCharsets.UTF_8);
            return result;
        } catch (Exception e) {
            throw new RuntimeException("解密失败", e);
        }
    }

    @Override
    public byte[] getSecretKey() {
        return new byte[16];
    }
}
